package com.xiaoyu.izf.controller;

import com.xiaoyu.izf.model.page.ParamListBean;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;


/**
 * 基础控制器
 * 
 * @author redmoon
 * 
 */
@Controller
public class BaseController {
	public ParamListBean getParamListBean(String str) {
		ParamListBean paramListBean = null;
		//System.out.println("---------------------------"+str);
		if(!StringUtils.isEmpty(str)){
			try {
				str = URLDecoder.decode(str, "utf-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			paramListBean = new ParamListBean();
			HashMap<String, String> hashMap = new HashMap<String, String>();
			String[] urlParam = str.split("&");
			for (int i = 0; i < urlParam.length; i++) {
				String[] p = urlParam[i].split("=");
				if("pageNo".equals(p[0])){
					paramListBean.setPageNo(Integer.parseInt(p[1]));
				}else if("pageLength".equals(p[0])){
					paramListBean.setPageLength(Integer.parseInt(p[1]));
				}else if("fieldName".equals(p[0])&&p.length==2){
					paramListBean.setFieldName(p[1]);
				}else if("compositorType".equals(p[0])&&p.length==2){
					paramListBean.setCompositorType(p[1]);
				}else if(p.length==1){
					hashMap.put(p[0], "");
				}else{
					hashMap.put(p[0], p[1]);
				}
			}
			paramListBean.setParam(hashMap);
		}
		return paramListBean;
	}

}
